﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using System.Windows.Media.Imaging;
//using System.IO.IsolatedStorage;

namespace Angerona
{
    public partial class MainPage : PhoneApplicationPage
    {

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        // Click

        /// <summary>
        /// Navigates to /Views/User.xaml
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_user_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/User.xaml", UriKind.Relative));
        }

        /// <summary>
        /// Navigates to /Views/Settings.xaml
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Settings_Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Settings.xaml", UriKind.Relative));
        }

        /// <summary>
        /// Navigates to /Views/Vehicles.xaml if the numbersOfVehicle inside the database is > 0.
        /// Otherwise, it will take the user to /Views/AddCar.xaml
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_vehicles_Click(object sender, RoutedEventArgs e)
        {
            if (App.ViewModel.getNumbersOfVehicles() == 0)
            {
                NavigationService.Navigate(new Uri("/Views/AddCar.xaml", UriKind.Relative));
            }
            else
            {
                // Carica la pagina contenente la "lista" di vetture
                NavigationService.Navigate(new Uri("/Views/Vehicles.xaml", UriKind.Relative));
            }
        }

                                ///////////////////////////     |
                                // HANDLE TOUCH ON ICONS //   \ | /
                                ///////////////////////////    \|/

        // VEHICLES

        /// <summary>
        /// Changes the icon with a negative one when the user press the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_vehicles_Pressed(object sender, RoutedEventArgs e)
        {
            vehicleImage.Source = new BitmapImage(new Uri("/Img/AppIcons/Angerona_62_62_INV.png", UriKind.RelativeOrAbsolute));
        }

        /// <summary>
        /// Changes the icon with a negative one when the user leaves the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_vehicles_Leaves(object sender, RoutedEventArgs e)
        {
            vehicleImage.Source = new BitmapImage(new Uri("/Img/AppIcons/Angerona_62_62.png", UriKind.RelativeOrAbsolute));
        }

        // UTENTE

        /// <summary>
        /// Changes the icon with a negative one when the user press the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_user_Pressed(object sender, RoutedEventArgs e)
        {
            userImage.Source = new BitmapImage(new Uri("/Img/AppIcons/user_100_100_INV.png", UriKind.RelativeOrAbsolute));
        }

        /// <summary>
        /// Changes the icon with a negative one when the user leaves the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_user_Leaves(object sender, RoutedEventArgs e)
        {
            userImage.Source = new BitmapImage(new Uri("/Img/AppIcons/user_100_100.png", UriKind.RelativeOrAbsolute));
        }

        //// IMPOSTAZIONI

        /// <summary>
        /// Changes the icon with a negative one when the user press the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_settings_Pressed(object sender, RoutedEventArgs e)
        {
            settingsImage.Source = new BitmapImage(new Uri("/Img/AppIcons/settings_100_100_INV.png", UriKind.RelativeOrAbsolute));
        }

        /// <summary>
        /// Changes the icon with a negative one when the user leaves the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_settings_Leaves(object sender, RoutedEventArgs e)
        {
            settingsImage.Source = new BitmapImage(new Uri("/Img/AppIcons/settings_100_100.png", UriKind.RelativeOrAbsolute));
        }

        //// AIUTO

        /// <summary>
        /// Changes the icon with a negative one when the user press the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_help_Pressed(object sender, RoutedEventArgs e)
        {
            helpImage.Source = new BitmapImage(new Uri("/Img/AppIcons/help_100_100_INV.png", UriKind.RelativeOrAbsolute));
        }

        /// <summary>
        /// Changes the icon with a negative one when the user leaves the respective button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_help_Leaves(object sender, RoutedEventArgs e)
        {
            helpImage.Source = new BitmapImage(new Uri("/Img/AppIcons/help_100_100.png", UriKind.RelativeOrAbsolute));
        }

        /// <summary>
        /// Writes the database when the user navigate to MainPage.xaml
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            App.ViewModel.SaveChangesToDB();
        }

    }
}